package com.bytedance.scenedemo;

import com.bytedance.scene.Scene;
import com.bytedance.scene.animation.animatorexecutor.DialogSceneAnimatorExecutor;
import com.bytedance.scene.dialog.alert.AlertDialogScene;
import com.bytedance.scene.dialog.alert.DialogInterface;
import com.bytedance.scene.interfaces.PushOptions;
import com.bytedance.scene.navigation.NavigationSceneGetter;
import com.bytedance.scenedemo.dialog.BottomSheetDialogSample;
import com.bytedance.scenedemo.dialog.DemoDialogScene;
import com.bytedance.scenedemo.dialog.DemoDialogWithDimScene;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;

public class DialogSamples extends Scene {
    @Override
    public Component onCreateView(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        Component component = scatter.parse(ResourceTable.Layout_dialog_sample, container, false);
        initComment(component);
        return component;
    }

    @Override
    public void onViewCreated(Component component, Intent intent) {
        initComment(component);
        super.onViewCreated(component, intent);
    }

    private void initComment(Component component) {
        Text text_title = (Text) component.findComponentById(ResourceTable.Id_text_title);
        text_title.setText(getClassName());
        final Button dialog_nobackground = (Button) component.findComponentById(ResourceTable.Id_btn_dialog_nobackground);
        final Button btn_dialog_background = (Button) component.findComponentById(ResourceTable.Id_btn_dialog_background);
        final Button btn_bottom_dialog = (Button) component.findComponentById(ResourceTable.Id_btn_bottom_dialog);
        final Button popwindows = (Button) component.findComponentById(ResourceTable.Id_popwindows);
        final Button alert_dialog = (Button) component.findComponentById(ResourceTable.Id_alert_dialog);
        /**
         * 对话框无背景色
         */
        dialog_nobackground.setClickedListener(component1 -> {
            NavigationSceneGetter.requireNavigationScene(DialogSamples.this).push(DemoDialogScene.class, null, new PushOptions.Builder()
                    .setTranslucent(true).setAnimation(new DialogSceneAnimatorExecutor()).build());
        });
        /**
         * 对话框有背景色
         */
        btn_dialog_background.setClickedListener(component1 -> {
            NavigationSceneGetter.requireNavigationScene(DialogSamples.this).push(DemoDialogWithDimScene.class, null, new PushOptions.Builder()
                    .setTranslucent(true).setAnimation(new DialogSceneAnimatorExecutor()).build());
        });
        /**
         * 底部BottomSheetDialog
         */
        btn_bottom_dialog.setClickedListener(component1 -> {
            BottomSheetDialogSample bottomSheetDialogSample = new BottomSheetDialogSample();
            bottomSheetDialogSample.show(this);
        });
        /**
         * popwindows
         */
        popwindows.setClickedListener(component1 -> {
            showToast("TODO");
        });
        /**
         *alertDialog
         */
        alert_dialog.setClickedListener(component1 -> {
            DialogInterface dialogInterface = new DialogInterface() {
                @Override
                public void onClickListen(Component component, int which) {
                    switch (which){
                        case BUTTON_POSITIVE:
                            showToast("click positive");
                            break;
                        case BUTTON_NEGATIVE:
                            showToast("click negative");
                            break;
                        case BUTTON_NEUTRAL:
                            showToast("click neutral");
                            break;
                    }
                }
            };

             new AlertDialogScene.Builder(DialogSamples.this).setTitle("this is title").setMessage("this is message").setNegativeButton("NEGATIVE",dialogInterface)
             .setNeutralButton("NEUTRAL",dialogInterface).setPositiveButton("POSITIVE",dialogInterface).show();
        });
    }
}
